/*
TestForward
Version 1.0
Description: Test class for ForwarController 
Author: Pratibh Prakash
Created Date: 11 Feb-2009
*/
@isTest
private class TestForward{
    /*
    forwardUserTest()
    Description: Test method for testing FowardController class, 4 test cases are used.
    */
    static testMethod void forwardUserTest(){
  
        HR__c objHR1 = new HR__c(First_Name__c='Test', Last_Name__c='Test', Email__c='Test@Test.com');
        HR__c objHR2 = new HR__c(First_Name__c='Test', Last_Name__c='Test', Email__c='Test@Test.com');
        insert(objHR1);
        
        /*
        Case 1: When HR__c.Id=null
        Generates condition for page redirect from new User page to HR__c detail view page.
        Adding two parameters to URL and respective values i.e 'hr' and 'newid'.
        */
        ApexPages.StandardController sc1 = new ApexPages.StandardController(objHR2);
        PageReference HRPage1 = new Pagereference('/apex/Forward?');
        HRPage1.getParameters().put('hr',objHR1.Id);
        HRPage1.getParameters().put('newid',userInfo.getUserId());
        //Test.setCurrentPage(HRPage1);
        System.currentPageReference().getParameters().put('hr',objHR1.Id);
        System.currentPageReference().getParameters().put('newid',userInfo.getUserId());

        ForwardController obj1 = new ForwardController(sc1);
        obj1.pageForward();
        
        /*
        Case 2: When HR__c.Id=null and no 'hr' parameter in URL.
        Generates condition for exception in constructor.
        Adding only one parameter to URL i.e 'newid'.
        */
        ApexPages.StandardController sc2 = new ApexPages.StandardController(objHR2);
        PageReference HRPage2 = new Pagereference('/apex/Forward?');
        HRPage2.getParameters().put('newid',userInfo.getUserId());
        System.currentPageReference().getParameters().put('newid',userInfo.getUserId());
        //Test.setCurrentPage(HRPage2);
        ForwardController obj2 = new ForwardController(sc2);
               
        /*
        Case 3: When HR__c.Id is not null
        Generates condition for page redirect from HR__c detail view page to new User page.
        */
        insert(objHR2);
        ApexPages.StandardController sc3 = new ApexPages.StandardController(objHR2);
        ForwardController obj3 = new ForwardController(sc3);
        obj3.pageForward();
        
        /*
        Case 4:When HR__c record is not found i.e query is returning zero records.
        Generates condition for exception in constructor.
        */
        ApexPages.StandardController sc4 = new ApexPages.StandardController(objHR2);
        delete(objHR2);//deleting record before constructor is called so that record is not found on query.
        ForwardController obj4 = new ForwardController(sc4);
      
        
          
     }
}